package pkg

import (
	"context"
	"github.com/openai/openai-go"
	"github.com/openai/openai-go/option"
)

const (
	APIKEY  = "bce-v3/ALTAK-eMWYNxnGs4fnBAEmuOger/35e4acd5957345c44c6b6559207709c3bd8ccad7"
	BASEURL = "https://qianfan.baidubce.com/v2/"
)

func Ernie(test string) string {
	client := openai.NewClient(
		// 替换下列示例中参数，将your_APIKey替换为真实值，如何获取API Key请查看https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Um2wxbaps#步骤二-获取api-key
		option.WithAPIKey(APIKEY),
		option.WithBaseURL(BASEURL), // 千帆ModelBuilder平台地址
	)

	stream := client.Chat.Completions.NewStreaming(context.TODO(), openai.ChatCompletionNewParams{
		// Messages信息
		Messages: openai.F([]openai.ChatCompletionMessageParamUnion{
			openai.ChatCompletionMessage{Content: test, Role: "user"},
		}),
		Model: openai.F("ernie-tiny-8k"), //模型对应的model值，请查看支持的模型列表：https://cloud.baidu.com/doc/WENXINWORKSHOP/s/wm7ltcvgc
	})
	var content string
	for stream.Next() {
		content += stream.Current().Choices[0].Delta.Content
	}
	return content

}
